package scenic.study.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by scenic on 2018/1/5.
 */
public class HttpConnect {


    public static void main(String args[]) throws IOException {
        String urlString = "https://github.com/scenic2010/MPAndroidChart/blob/master/MPChartLib/build.gradle";

        URL url = new URL(urlString);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
        connection.setUseCaches(false);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setRequestProperty("Upgrade", "websocket");
        connection.setRequestProperty("Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setRequestMethod("GET");
        connection.connect();

        InputStream input = connection.getInputStream();

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input));
        String tmp;
        while ((tmp = bufferedReader.readLine()) != null){
            System.out.println(tmp);
        }
        System.out.println(input);
    }
}
